<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                <el-breadcrumb-item>用户管理</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框杀杀杀
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="CustomerIssuesFormData"  class="demo-form-inline">
                <el-form-item >
                    <el-input v-model="CustomerIssuesFormData.submodule" placeholder="请输入名字"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="chaxun">查询</el-button>
                    <el-button type="primary" @click="insert">添加</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        align="center"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="编号"
                            align="center"
                            sortable
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="submodule"
                            label="所属模块"
                            align="center"
                            sortable
                            width="180">
                    </el-table-column>

                    <el-table-column
                            prop="question"
                            label="问题"
                            align="center"
                            sortable
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="answer"
                            label="答案"
                            align="center"
                            sortable
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="addtime"
                            label="添加时间"
                            align="center"
                            sortable
                            width="180">
                    </el-table-column>
                    <el-table-column label="操作" width="195" align="center">
                        <template slot-scope="scope">
                            <el-button type="primary" icon="el-icon-edit" circle @click="selectById(scope.row.id)"></el-button>
                            <el-button type="danger" icon="el-icon-delete" circle @click="deleteById(scope.row.id)"></el-button>
                            <!--                            <el-button type="warning" icon="el-icon-star-off" circle @click="showUserRole(scope.row.userId)"></el-button>-->
                        </template>
                    </el-table-column>
                </el-table>

                <!--                分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>


            </template>
        </el-card>



        <el-dialog
                title="提示"
                :visible.sync="editDialogVisible"
                width="30%"
                :before-close="handleClose"
        >
            <!--            model:表单数据-->
            <el-form  label-width="80px" :model="CustomerIssuesForm" :rules="formRules" ref="formRef" >
                <el-form-item label="id" style="display: none">
                    <el-input v-model="CustomerIssuesForm.id"  ></el-input>
                </el-form-item>
                <el-form-item label="所属模块"  prop="submodule" :error="existError">
                    <el-select v-model="CustomerIssuesForm.submodule" placeholder="请选择所属模块" >
                        <el-option
                                v-for="itemes in submoduleArray"
                                :key="itemes.name"
                                :label="itemes.submodule"
                                :value="itemes.name">
                        </el-option>

                    </el-select>
                </el-form-item>
                <el-form-item label="问题" prop="question" >
                    <el-input v-model="CustomerIssuesForm.question"></el-input>
                </el-form-item>
                <el-form-item label="回答" prop="answer">
                    <el-input v-model="CustomerIssuesForm.answer"></el-input>
                </el-form-item>
                <el-form-item label="添加时间" prop="addtime">
                    <el-date-picker
                            v-model="CustomerIssuesForm.addtime"
                            type="datetime"
                            placeholder="选择日期时间">
                    </el-date-picker>






                </el-form-item>


            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="reset">取 消</el-button>
                <el-button type="primary" @click="formSubmit">确 定</el-button>
              </span>
        </el-dialog>



    </div>
</template>

<script>
    export default {
        name: "CustomerIssues",
        data(){
            return{
                editDialogVisible:false,
                //条件搜索对象
                CustomerIssuesFormData:{},
                //表格数据
                tableData:[],
                //每页显示的条数
                pageSize: 5,
                //当前的显示的页码
                currentPage:1,
                //总条数
                total:0,
                //客户问答的查询表单
                CustomerIssuesForm:{},
                //所属模块规则
                submoduleArray:[{name:"服务规则",submodule:"服务规则"},{name:"常见问题",submodule:"常见问题"},{name:"新手上路",submodule:"新手上路"},{name:"其它模块",submodule:"其它模块"}],
                //错误信息提示
                existError:"",
                //表单校验
                formRules: {
                    submodule:[{required:true,message:"请输入所属模块",trigger:'blur'}],
                    addtime:[{required:true,message:"请添加时间",trigger:'blur'}],
                    question:[{required:true,message:"请输入问题",trigger:'blur'}],
                    answer:[{required:true,message:"请输入答案",trigger:'blur'}],
                }
            }
        },
        //表单加载时就执行
        created() {
            this.selectall();
        },
        methods:{


        //提交增加和修改的表单校验
            formSubmit(){
                var that=this;
                this.$refs.formRef.validate((valid)=> {
                    if (valid) {
                        if (this.CustomerIssuesForm.id != null) {
                            this.$http.put("marketing/customer/updatecustomerissues", this.CustomerIssuesForm).then(function () {
                                that.editDialogVisible = false;
                                that.CustomerIssuesForm = {};
                                that.selectall();
                            })
                        } else {
                            this.$http.post("marketing/customer/insertcustomerissues", this.CustomerIssuesForm).then(function () {
                                that.editDialogVisible = false;
                                that.selectall();
                            })
                        }
                    }
                });
            },
            //查询所有
            selectall(){
                var that=this;
                this.$http.post(`marketing/customer/selectpage/${this.currentPage}/${this.pageSize}`,this.CustomerIssuesFormData).then(function (returnResult) {
                    that.total=returnResult.data.result.total;
                    that.tableData=returnResult.data.result.records;
                    console.log(that.tableData)

                })
            },
            chaxun(){
                var that=this;
                this.$http.get(`marketing/customer/selectall`,this.CustomerIssuesFormData).then(function () {
                    that.selectall();
                })

            },
            //增加
            insert(){
                this.editDialogVisible=true;
                this.CustomerIssuesForm={};
            },
            //删除
            deleteById(id){
                var that=this;
                this.$http.delete("marketing/customer?id="+id).then(function () {
                    that.selectall();
                    that.$message.success("删除成功");

                })
            },
            //通过id查找回显
            selectById(id){
                var that=this;
                 this.editDialogVisible=true;
                this.$http.get(`marketing/customer/selectbyid/${id}`).then(function (returnResult) {
                    that.CustomerIssuesForm=returnResult.data.result.previews;
                    console.log(returnResult)
                })
            },
            //当前页条数
            handleSizeChange(v){
                this.pageSize=v;
                this.selectall();
            },
            //当前页
            handleCurrentChange(v){
                this.currentPage=v;
                this.selectall();
            },
            //可以消除红色字体
            reset(){
                this.editDialogVisible=false;
                this.$refs.CustomerIssuesForm.resetFields();
            },
            //提示框
            handleClose(){
                this.editDialogVisible=false;
                this.$refs.formRef.resetFields();
            },













        }
    }
</script>

<style scoped>

</style>